﻿<?php
	// session_start();
	include "connect.php";
	
	if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: ad-dangnhap.php");
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cập Nhật Bộ Môn</title>
 <script type="text/javascript" src="ajax/ajax.js"></script> 
</head>

<body>

<table width="700" align="center">
	<tr > 
	   <td height="40" align="right"><a href="ad-trangchu.php?nav=thembm" class="style4"><img src="image/them.png" />&nbsp; Thêm Bộ Môn</a></td>
	</tr>

	<tr>
		<td>
		<!--chứa bảng tìm kiếm bo mon -->
			<table width="700" align="center" border="0" style="border:1px solid #0066FF"  cellspacing="0">
						
					  <tr> 
							<td height="25" colspan="3" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
								<span class="style2">Tìm Bộ Môn Cập nhật</span></td>
					  </tr>
					
						<tr bordercolor="#FFFFFF"> 
							  <td colspan="3" height="50" align="center" style="font-size:18px">
							  
									  <form name="f" method="post">
									  <table>
											 <tr>
															<td height="30"> 
																 Khoa :  
															</td>
															<td>		
															<select name="khoa" id="khoa" onchange="showten(this.value)">
																<?php
																		$sql=mysql_query("select * from khoa"); 
																		while($r=mysql_fetch_row($sql))
																		{
																			  $makhoa=$r[0];
																			  $tenkhoa=$r[1];
																?>
																			  <option value="<?php echo $makhoa; ?>"><?php echo $tenkhoa; ?></option>
																<?php 
																		}
																?>
																 <option value="" selected="selected"> - Chọn Khoa -</option>
														   </select></td>
												</tr>
												
											   <tr>
															<td height="30">
																  Bộ Môn: 
															</td>
															<td >
															    <div id="bomon"></div>
															</td>
												</tr>
												
												<tr>
														<td colspan="2" align="center">  
													   <input name="tk" type="submit"  id="tk" value="   Tìm Kiếm  " />
													   </td>
											   </tr>
											   
											   </table>
									  </form>
							 </td>
							
					  </tr>
					  
					
			</table>
		</td>
	</tr>
</table>

<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>

<?php
     $bm=@$_POST["bomon"];
	 if($bm!="")
	 {
			        $sql_query=mysql_query("select ma_bm,ten_bm,a.ma_khoa,ten_khoa from `bo mon` a,`khoa` b where ma_bm = '$bm' and a.ma_khoa=b.ma_khoa  ");
	
				    $r=mysql_fetch_row($sql_query);
					$mabm=$r[0];
					$tenbm=$r[1];
					$mak=$r[2];
					$tenk=$r[3];
					
				
				?>
									 <form name="f" method="post" action="" onsubmit="">
							  <table width="400" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0">
									
								  <tr> 
										<td height="30" colspan="2" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
											<span style="font-size:24px; color:#FFFFFF; font-weight:bold;">Thông tin Bộ môn</span></td>
								  </tr>
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
									
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">Mã Bộ Môn:</td>
									  <td align="left"><input type="text" name="mabm" value="<?php echo $mabm; ?>"  class="mau" readonly="" /></td>
								  </tr>
								  
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Tên Bộ Môn:</td>
									 <td align="left"><input type="text" name="tenbm" value="<?php echo $tenbm; ?>" size="40"   /></td>
								  </tr>
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px">Tên Khoa:</td>
									  <td align="left">
									  		<select name="k">
											                    <?php
																		$sql=mysql_query("select * from khoa where ma_khoa != '$mak'"); 
																		while($r=mysql_fetch_row($sql))
																		{
																			  $makhoa=$r[0];
																			  $tenkhoa=$r[1];
																?>
																 <option value=" <?php echo $makhoa; ?>"><?php echo  $tenkhoa; ?></option>
																<?php 
																		}
													
																?>
																 <option value="<?php echo $mak; ?>" selected="selected"> <?php echo $tenk; ?></option>                                                         
											</select>
									  </td>
								  </tr>
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
								  
								  <tr bordercolor="#FFFFFF">
									  <td  align="right" height="30"><input type="submit" value="Cập nhật" name="cn" /></td>
									  <td align="center"><input type="reset" value="Làm Lại" name="huy" /></td>
								 </tr>
								
						</table>
				  </form>	
				  
				<?php 
}
				?>  
				
<table>
     <tr>
	     <td height="30"></td>
	 </tr>
</table>	
<?php 
                if(isset($_POST["cn"]))
				{
				          $ma=$_POST["mabm"];
				          $ten=$_POST["tenbm"];
						  $mak=$_POST["k"];
						  $kq=mysql_query(" update `bo mon` set ten_bm='$ten',ma_khoa='$mak' where ma_bm='$ma' ");
						  echo"<script type='text/javascript'>alert('Cap Nhat Thanh Cong')</script>";
		                  echo'<meta http-equiv="refresh" content="0;URL=ad-trangchu.php?nav=bomon">';
						  
				}
?>
</body>
</html>
